package main.chapter2

class Complex(var real: Double, var imaginary: Double) {
    //定义一个运算符加法
    operator fun plus(anotherComplex: Complex): Complex {
        return Complex(real + anotherComplex.real, imaginary + anotherComplex.imaginary)
    }

    operator fun plus(other: Int): Complex {
        return Complex(real + other, imaginary)
    }

    override fun toString(): String {
        return "$real+${imaginary}i"
    }
}

fun main() {
    val c1 = Complex(3.0, 4.0) //3+4i
    val c2 = Complex(2.0, 7.5) //2+7.5i
    println(c1 + c2)
    println(c1 + 5)
}


